go to previous page   go to home page   go to next page

Answer:

int getWidth()
int getHeight()

Scaling the Start

graph of sin x

So now rather than using hard-coded values for width and height, use the actual values of the panel.

Say that x is the current value in the range 0.0 to 2*Math.PI. Then Math.sin( x ) is the function values in the range -1.0 to 1.0. The following code scales those values to fit the Java panel

The location (startXint, startYint) is the left end of a small line segment that is part of the curve.


startX = x;
startY = Math.sin( x );

int startXint = (int)(  startX * (width-1)/(2*Math.PI) );
int startYint = (int)( -startY * (height-1)/2.0 + (height-1)/2.0 );

QUESTION 12:

The right end of the line segment is computed by incrementing x by a small amount contained in inc. What does that look like?

endX   = startX + ;
endY   = Math.sin(  );